package com.javabase.y2022.m04.day0425.v2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/4/25 下午 02:35
 * @version: 1.0
 */
public class Solution {
    public static void main(String[] args) {

    }

    private HashMap<Integer, List<Integer>> map = new HashMap<>();
    private Random random;
    public Solution(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            if(map.get(nums[i]) == null){
                ArrayList<Integer> list = new ArrayList<>();
                map.put(nums[i], list);
                list.add(i);
            }else{
                map.get(nums[i]).add(i);
            }
        }
    }

    public int pick(int target) {
        List<Integer> list = map.get(target);
        return list.get(random.nextInt(list.size()));
    }
}
